package com.kmu.wmy.dao.impl;

import com.kmu.wmy.dao.LoginDao;
import com.kmu.wmy.entity.LoginDetail;
import com.kmu.wmy.factory.HibernateFactory;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.query.Query;

public class LoginDaoImpl implements LoginDao {
    @Override
    public LoginDetail validateUserInfo(String studentNo, String token) {
        Session session = HibernateFactory.getSession();
        Transaction transaction = session.beginTransaction();
        LoginDetail loginDetail = null;
        Query query = session.createQuery("from LoginDetail where studentNo = ?1 and token = ?2");
        query.setParameter(1, studentNo);
        query.setParameter(2, token);
        loginDetail = (LoginDetail) query.uniqueResult();
        transaction.commit();
        session.close();
        return loginDetail;
    }
}